﻿#include "prj_manager_widget.h"
#include "ui_prj_manager_widget.h"
#include "easylogging++.h"

PrjManagerWidget::PrjManagerWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::PrjManagerWidget),
    m_prjTableWidget(new PrjManagerTableWidget),
    m_prjDetailWidget(new PrjManagerDetailWidget)
{
    ui->setupUi(this);
    initUi();
    initEvents();
}

PrjManagerWidget::~PrjManagerWidget()
{
    delete ui;
}

void PrjManagerWidget::initUi()
{
    ui->stackedWidget->addWidget(m_prjTableWidget);
    ui->stackedWidget->addWidget(m_prjDetailWidget);

    ui->stackedWidget->setCurrentWidget(m_prjTableWidget);
}

void PrjManagerWidget::initEvents()
{
    connect(m_prjTableWidget, &PrjManagerTableWidget::prjDoubleClicked,
            this, [=](QString prjName, QString uuid) {
        m_prjDetailWidget->setProject(prjName, uuid);
        ui->stackedWidget->setCurrentWidget(m_prjDetailWidget);
    });

    connect(m_prjDetailWidget, &PrjManagerDetailWidget::backToPrj, this, [=]() {
        ui->stackedWidget->setCurrentWidget(m_prjTableWidget);
    });
}
